package com.wondersgroup.wssuap.sso.client;

import java.util.Properties;


public class SsoClientConfig {
	public static SsoClientConfig insatance;
	public static SsoClientConfig getInsatance() {
		return insatance;
	}
	
	public static void init(Properties props){
		insatance=new SsoClientConfig(props);
	}
	
	private SsoClientConfig(Properties props){
		ssoLoginUrl = props.getProperty("ssoLoginUrl");
		ticketParam = props.getProperty("ticketParam");
		
		loginedSessionAttribute = props.getProperty("loginedSessionAttribute");
		ssoValidateUrl = props.getProperty("ssoValidateUrl");
		String ssoJoinedCallbackClass =props.getProperty("ssoJoinedCallback");
		if (ssoLoginUrl == null || ssoLoginUrl.trim().length() == 0) {
			throw new IllegalArgumentException("Property 'ssoLoginUrl' should not be empty");
		}
		if (loginedSessionAttribute == null || loginedSessionAttribute.trim().length() == 0) {
			throw new IllegalArgumentException("Property 'loginedSessionAttribute' should not be empty");
		}
		if (loginedSessionAttribute == null || loginedSessionAttribute.trim().length() == 0) {
			throw new IllegalArgumentException("Property 'loginedSessionAttribute' should not be empty");
		}
		if (ssoValidateUrl == null || ssoValidateUrl.trim().length() == 0) {
			throw new IllegalArgumentException("Property 'ssoValidateUrl' should not be empty");
		}
		try {
			ssoJoinedCallback = (SsoJoinedCallback) Class.forName(ssoJoinedCallbackClass).newInstance();
		}
		catch (Exception e) {
			throw new IllegalArgumentException(String.format(
				"Error occur when creating SsoJoinedCallback instance  of '%s'", ssoJoinedCallbackClass), e);
		}	
	}
	
	private String ticketParam;

	private String ssoLoginUrl;
	
	private String ssoValidateUrl;

	private SsoJoinedCallback ssoJoinedCallback;

	private String loginedSessionAttribute;

	public String getTicketParam() {
		
		return ticketParam;
	}

	public String getSsoLoginUrl() {
		return ssoLoginUrl;
	}

	public String getSsoValidateUrl() {
		return ssoValidateUrl;
	}

	public SsoJoinedCallback getSsoJoinedCallback() {
		return ssoJoinedCallback;
	}

	public String getLoginedSessionAttribute() {
		return loginedSessionAttribute;
	}
}
